<?php  
  

function get_tanggal_by_periode_id(){
	$periode_id=isset($_GET['periode_id']) ? (int) $_GET['periode_id'] : get_periode_gaji() ;
	$periodes = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periodes['tanggal']));
	$tahun = $periodes['tahun'] ;
	return sprintf( '%02d',$bulan).'-'.$tahun ;
}

function list_komponen($start , $end , $page){
	$periode_gaji_id=get_periode_gaji() ;
	$periode_id=isset($_GET['periode_id']) ? (int) $_GET['periode_id'] : $periode_gaji_id ;
	if( $periode_gaji_id==$periode_id ){
		$kalkulasi_periode=0;
	}else{
		$kalkulasi_periode=$periode_id;
	}
	$tipes = array(
		'1'=>'Tunjangan',
		'2'=>'Potongan',
		'3'=>'Iuran',
	);	

	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:25px'),  
		'Nama Komponen'=>array('style'=>'text-align:left;border-bottom:2px solid;width:350px'),  
		'Tipe'=>array('style'=>'text-align:center;border-bottom:2px solid;width:120px'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:140px'),  
		 
	);

	$query = "SELECT komponen_gaji_id, nama_komponen_gaji, tipe 
			FROM pr_komponen_gaji
			ORDER BY tipe, komponen_gaji_id LIMIT $start , $end"
	;
	
	$result = my_query($query);
	$i=0;
	while($ey = my_fetch_array($result)){
		$komponen_id=$ey['komponen_gaji_id'];
		$query = "SELECT SUM(kalkulasi) as kalkulasi 
			FROM pr_gaji_komponen  
			WHERE komponen_id={$komponen_id}
			AND periode_id={$kalkulasi_periode}" ;
		$res = my_fetch_array(my_query($query));
		$i++;
		$row[] = array(
				'no'=>  '<div style="width:25px;text-align:center;">'.$i.'</div>',  
				'gd'=>  $ey['nama_komponen_gaji'] ,
				'tipe'=>$tipes[$ey['tipe']],
				'bulan_ini'=>  '<div style="width:139px;text-align:right;">'.rp_format($res['kalkulasi']) .'</div>' ,      
			 
		); 
	}
	$query = "SELECT komponen_gaji_id, nama_komponen_gaji, tipe 
			FROM pr_komponen_gaji
			ORDER BY tipe, komponen_gaji_id"
	;	
	$result = my_query($query);
	$total = my_num_rows($result) + 1; 
	$limit = 30;
	$total_page = ceil($total/$limit) -1; 
	if($page ==  $total_page  ){
		$i++;
		$queryw = "SELECT SUM(kalkulasi) as kalkulasi 
		FROM pr_gaji_komponen  
		WHERE periode_id={$kalkulasi_periode}" ;
		$resultxw = my_query($queryw);
		$resw = my_fetch_array($resultxw); 
		$row[] = array(
			'no'=>  '<div style="width:25px;text-align:center;">'.$i.'</div>',    
			'gd'=>  'Take home pay',
			'tipe'=>'Cash paid',
			'bulan_ini'=>  position_text_align (rp_format($resw['kalkulasi']) ,'right'), 
		);
	}
	$datas = table_cetak_rows($row); 
	return table_cetak_builder($header , $datas ,  6   );
}
 
?>
<style type="text/css">
<!--

	table.page_header {width: 100%; border: none; background-color: #CDCDCD; border-bottom: solid 1mm #000; padding: 2mm }
	table.page_footer {width: 100%; border: none;  border-top: solid 1mm #000; padding: 2mm}
div.zone
{
	border: solid 2mm #66AACC;
	border-radius: 3mm;
	padding: 1mm;
	background-color: #FFEEEE;
	color: #440000;
}
div.zone_over
{
	width: 30mm;
	height: 35mm;
	overflow: hidden;
}

-->
</style>  
	<?php 
$query = "SELECT komponen_gaji_id, nama_komponen_gaji, tipe 
			FROM pr_komponen_gaji
			ORDER BY tipe, komponen_gaji_id ";
	$result = my_query($query);
	$total = my_num_rows($result) + 1; 
	$limit = 30;
	$total_page = ceil($total/$limit) -1; 
	
	 
	for($i = 0; $i<=  $total_page  ;$i++):
	$start =  ( $i * $limit );

	
?>	  	 
<page style="font-size: 10pt">
	<page_footer>
		<table class="page_footer">
			<tr>
				<td style="width: 33%; text-align: left;">
					 HRIS RSKM 
				</td>
				<td style="width: 34%; text-align: center">
					page [[page_cu]]/[[page_nb]]
				</td>
				<td style="width: 33%; text-align: right">
					M A P &copy; 2010 - <?php echo date('Y'); ?>
				</td>
			</tr>
		</table>
	</page_footer>
	<?php if($i ==0){ ?>
	 
	<div style="width: 100%; text-align:center; padding:2px; font-size: 13pt ;">REKAP BIAYA KOMPONEN GAJI<br> </div>
	
	<br><?php } ?>
	<table style="width:100%;"> 
	<tr>
		<td style="font-size:12px;width:35%;height:20px;">Periode Gaji</td>
		<td style="width:65%"><?php echo get_tanggal_by_periode_id();?></td>
	</tr>
	</table><br>
	
	<?php  echo list_komponen($start , $limit , $i) ; ?> 
</page> 
<?php endfor; ?>